<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="工号" prop="networkSafeId">
        <el-input
          v-model="queryParams.networkSafeId"
          placeholder="请输入工号"
          clearable
          size="medium"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
       <el-form-item label="专案名称" prop="ictCode" >
         <el-select v-model="queryParams.ictCode"  filterable allow-create placeholder="请选择或输入ICT代码"
          clearable :style="{width: '100%'}">
           <el-option v-for="(item, index) in ictCodeOptions" :key="index" :label="item.label"  @keyup.enter.native="handleQuery"
             :value="item.value" :disabled="item.disabled" ></el-option>
         </el-select>
        </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="medium" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8" >
      <el-col :span="1.5" >
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="medium"
          @click="handleAdd"
          v-hasPermi="['info:projectMgmt:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5" >
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="medium"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['info:projectMgmt:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="projectMgmtList" @selection-change="handleSelectionChange">
      <el-table-column label="项目序号" align="center" prop="pId" sortable />
      <el-table-column label="BU" align="center" prop="bu" />
      <el-table-column label="ICT代码" align="center" prop="ictCode" />
      <el-table-column label="BUD代码" align="center" prop="budCode" />
      <el-table-column label="主导BU" align="center" prop="leadingBu" />
      <el-table-column label="资安DRI" align="center" prop="networkSafeId" />
      <el-table-column label="管控等级" align="center" prop="levelControl" />
      <el-table-column label="主要区域" align="center" prop="mainRegion" />
      <el-table-column label="扩展区域" align="center" prop="expansionRegion" />
      <el-table-column label="待审批lab" align="center" prop="approvalPendingLab" />
      <el-table-column label="专案进度" align="center" prop="projectProgress" />
      <el-table-column label="BU窗口" align="center" prop="buDriName" />
      <el-table-column label="安保窗口" align="center" prop="securityName" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['info:projectMgmt:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['info:projectMgmt:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改专案管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" >
<!--        <el-form-item label="BU" prop="bu" class="dialogHeight">
          <el-select v-model="form.bu"  filterable allow-create placeholder="请选择BU或者输入BU"
           clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in buOptions" :key="index" :label="item.label"
              :value="item.value" :disabled="item.disabled" ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="BU" prop="bu" class="dialogHeight">
          <el-select v-model="form.bu"  filterable allow-create placeholder="请选择BU或者输入BU"
                     clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in buOptions" :key="index" :label="item.label"
                       :value="item.value" :disabled="item.disabled" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="ICT代码" prop="ictCode" class="dialogHeight">
          <el-select v-model="form.ictCode"  filterable allow-create placeholder="请选择ICT代码或者输入ICT代码"
           clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in ictCodeOptions" :key="index" :label="item.label"
              :value="item.value" :disabled="item.disabled" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="BUD代码" prop="budCode" class="dialogHeight">
          <el-select v-model="form.budCode"  filterable allow-create placeholder="请选择BUD代码或者输入BUD代码"
           clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in budCodeOptions" :key="index" :label="item.label"
              :value="item.value" :disabled="item.disabled" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="主导BU" prop="leadingBu" class="dialogHeight">
          <el-select v-model="form.leadingBu"  filterable allow-create placeholder="请选择主导BU或者输入主导BU"
           clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in leadingBuOptions" :key="index" :label="item.label"
              :value="item.value" :disabled="item.disabled" ></el-option>
          </el-select>
        </el-form-item>
       <el-form-item label="资安DRI" prop="networkSafeId" class="dialogHeight">
          <el-input v-model="form.networkSafeId" placeholder="请输入资安DRI工号进行查询" @input="searchFile()" id="userIdInput"/>
        </el-form-item>
        <el-form-item label="管控等级" prop="levelControl" class="dialogHeight">
          <el-select v-model="form.levelControl"  filterable allow-create placeholder="请选择管控等级或者输入管控等级"
           clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in levelControlOptions" :key="index" :label="item.label"
              :value="item.value" :disabled="item.disabled" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="主要区域" prop="mainRegion" class="dialogHeight">
          <el-input v-model="form.mainRegion" placeholder="请输入主要区域" />
        </el-form-item>
        <el-form-item label="扩展区域" prop="expansionRegion" class="dialogHeight">
          <el-input v-model="form.expansionRegion" placeholder="请输入扩展区域" />
        </el-form-item>
        <el-form-item label="待审批" prop="approvalPendingLab" class="dialogHeight">
          <el-input v-model="form.approvalPendingLab" placeholder="请输入待审批lab"/>
        </el-form-item>
        <el-form-item label="专案进度" prop="projectProgress" class="dialogHeight">
          <el-select v-model="form.projectProgress"  filterable allow-create placeholder="请选择专案进度或者输入专案进度"
           clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in projectProgressOptions" :key="index" :label="item.label"
              :value="item.value" :disabled="item.disabled" ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="BU窗口" prop="buDriName" class="dialogHeight">
          <el-input v-model="form.buDriName" placeholder="请输入BU窗口名称" />
        </el-form-item>
        <el-form-item label="安保窗口" prop="securityName" class="dialogHeight">
          <el-input v-model="form.securityName" placeholder="请输入安保DRI姓名" />
        </el-form-item>
        <el-form-item label="备注" prop="remark" class="dialogHeight">
          <el-input v-model="form.remark" placeholder="请输入备注" type="textarea"   :autosize="{minRows: 2, maxRows: 3}" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="dialogtitle"  :visible.sync="dialogTableVisible"  width="1000px"  center >
        <el-table :data="gridData">
          <el-table-column property="empId" label="员工工号" width="150"></el-table-column>
          <el-table-column property="empName" label="员工姓名" width="200"></el-table-column>
          <el-table-column property="unitList" label="员工组织" width="250"></el-table-column>
          <el-table-column property="unitName" label="员工部门" width="200"></el-table-column>
          <el-table-column property="title" label="员工职级" width="200"></el-table-column>
        </el-table>
    </el-dialog>

  </div>
</template>

<script>
import { listMgr, getMgr, delMgr, addMgr, updateMgr, exportMgr,getoptionValue,getuserIdValue }  from  "@/api/info/projectMgmt";

export default {
  name: "ProjectMgmt",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专案管理表格数据
      projectMgmtList: [],
      gridData: [],
      // 弹出层标题
      title: "",
      dialogtitle: "用户详情信息",
      // 是否显示弹出层
      open: false,

      dialogTableVisible: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bu: null,
        ictCode: null,
        budCode: null,
        leadingBu: null,
        networkSafeId: null,
        networkSafeName: null,
        levelControl: null,
        mainRegion: null,
        expansionRegion: null,
        approvalPendingLab: null,
        projectProgress: null,
        buDriId: null,
        buDriName: null,
        securityId: null,
        securityName: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      // 表单校验
      rules: {
        bu: [
          { required: true, message: "BU不能为空", trigger: "blur" }
        ],
        ictCode: [
          { required: true, message: "ICT代码不能为空", trigger: "blur" }
        ],
        budCode: [
          { required: true, message: "BUD代码不能为空", trigger: "blur" }
        ],
        leadingBu: [
          { required: true, message: "主导BU不能为空", trigger: "blur" }
        ],
        networkSafeId: [
          { required: true, message: "资安DRI工号不能为空", trigger: "blur" }
        ],
        levelControl: [
          { required: true, message: "管控等级不能为空", trigger: "blur" }
        ],
        mainRegion: [
          { required: true, message: "主要区域不能为空", trigger: "blur" }
        ],
        expansionRegion: [
          { required: true, message: "扩展区域不能为空", trigger: "blur" }
        ],
        approvalPendingLab: [
          { required: true, message: "待审批lab不能为空", trigger: "blur" }
        ],
        projectProgress: [
          { required: true, message: "专案进度不能为空", trigger: "blur" }
        ],
        buDriName: [
          { required: true, message: "BU窗口名称不能为空", trigger: "blur" }
        ],
        securityName: [
          { required: true, message: "安保DRI姓名不能为空", trigger: "blur" }
        ],
        remark: [
          { required: true, message: "备注不能为空", trigger: "blur" }
        ],
      },
      networkSafeNameOptions: [{
        "label": "专案选项1",
        "value": 0
      }, {
        "label": "专案选项2",
        "value": 1
      }, {
        "label": "专案选项3",
        "value": 2
      }],
      buOptions: [],
      leadingBuOptions: [],
      levelControlOptions: [],
      projectProgressOptions: [],
      ictCodeOptions: [],
      budCodeOptions: [],
    };
  },
  created() {

    this.getList();
    this.getictCodeList()
  },
  methods: {
    /** 查询专案管理列表 */
    getList() {
      this.loading = true;
      listMgr(this.queryParams).then(response => {
        this.projectMgmtList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询iCT代码下拉框 */
    getictCodeList() {
      this.loading = true;
       let str="ictCode"
      getoptionValue(str).then(response => {

         this.ictCodeOptions = response.data;
         this.loading = false;
      });
    },
    /** 查询BUD代码下拉框 */
    getbudCodeList() {
      this.loading = true;
       let str="budCode"
      getoptionValue(str).then(response => {
         this.budCodeOptions = response.data;
         this.loading = false;
      });
    },

    /** 查询BU下拉框 */
    getBuList() {
      this.loading = true;
       let str="bu"
      getoptionValue(str).then(response => {
         this.buOptions = response.data;
         this.loading = false;
      });
    },
    /** 查询主导bu下拉框 */
    getleadingBuList() {
      this.loading = true;
       let str="leadingBu"
        getoptionValue(str).then(response => {
        this.leadingBuOptions = response.data;
        this.loading = false;
      });
    },
    /** 查询管控等级下拉框 */
    getlevelControlList() {
      this.loading = true;
       let str="levelControl"
      getoptionValue(str).then(response => {
        this.levelControlOptions = response.data;
        this.loading = false;
      });
    },
    /** 查询专案进度下拉框 */
    getprojectProgressList() {
      this.loading = true;
       let Progressstr="projectProgress"
      getoptionValue(Progressstr).then(response => {
        this.projectProgressOptions = response.data;
        this.loading = false;
      });
    },

   /** 查询输入工号调取方法展示数据 */
    searchFile() {
     let userIdData=document.getElementById("userIdInput").value;
          getuserIdValue(userIdData).then( response => {
          this.dialogTableVisible=true;
          this.gridData = response.data;
          this.loading = false;
      });

    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pId: null,
        bu: null,
        ictCode: null,
        budCode: null,
        leadingBu: null,
        networkSafeId: null,
        networkSafeName: null,
        levelControl: null,
        mainRegion: null,
        expansionRegion: null,
        approvalPendingLab: null,
        projectProgress: null,
        buDriId: null,
        buDriName: null,
        securityId: null,
        securityName: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.pId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getictCodeList()
      this.getbudCodeList()
      this.getBuList()
      this.getleadingBuList()
      this.getlevelControlList()
      this.getprojectProgressList()
      this.open = true;
      this.title = "添加专案管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getictCodeList()
      this.getbudCodeList()
      this.getBuList()
      this.getleadingBuList()
      this.getlevelControlList()
      this.getprojectProgressList()
      const pId = row.pId || this.ids
      getMgr(pId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改专案管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.pId != null) {
            updateMgr(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMgr(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const pIds = row.pId || this.ids;
      this.$modal.confirm('是否确认删除专案管理编号为"' + pIds + '"的数据项？').then(function() {
        return delMgr(pIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有专案管理数据项？').then(() => {
        this.exportLoading = true;
        return exportMgr(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
<style>
  .dialogHeight {
    margin-bottom: 5px;
  }
</style>
